<?php

namespace App\Admin\Controllers\education;

use App\Admin\Actions\Row\AuditActions;
use App\Models\AdminEducation;
use App\Models\AdminManager;
use Dcat\Admin\Grid;
use Dcat\Admin\Http\Controllers\AdminController;
use Dcat\Admin\Widgets\Card;

class AuditController extends AdminController
{
    protected $title = "项目";

    protected $translation = 'admin-manager';
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(AdminEducation::with(['user', 'admin']), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('cover_path') -> image('','100');
            $grid->column('info','基本信息') -> display(
                function(){
                    return <<<HTML
                       <div style="line-height: 1.8; font-size: 14px; text-align: left;">
                            <div><strong>标题：</strong> {$this->title}</div>
                            <div><strong>发布人：</strong> {$this->admin->name} - {$this->admin->phone}</div>
                            <div><strong>负责人：</strong> {$this->user->name} - {$this->user->phone}</div>
                        </div>
                    HTML;
                }
            );
            $grid->column('other','项目信息') -> display(
                function(){
                    return <<<HTML
                       <div style="line-height: 1.8; font-size: 14px; text-align: left;">
                            <div><strong>已筹：</strong> {$this->target_amount}</div>
                            <div><strong>目标：</strong> {$this->target_amount}</div>
                            <div><strong>划拨：</strong> {$this->target_amount}</div>
                        </div>
                    HTML;
                }
            );
            $grid->column('content') -> display('查看') -> modal(
                function ($modal) {
                    $modal->title($this->title);
                    $content = <<<HTML
                        <div class="rich-content">
                            {$this->content}
                        </div>
                        <style>
                            .rich-content {
                                width: 100%;
                                word-break: break-word;
                            }
                            .rich-content img {
                                max-width: 100%;
                                height: auto;
                                display: block;
                            }
                        </style>
                    HTML;
                    $card = new Card(null, $content);
                    return "<div style='padding:10px 10px 0'>$card</div>";
                }
            );
            $grid->column('audit_status','审核原因') -> display('查看') -> modal(
                function () {
                    $content = $this -> audit_response;
                    $card = new Card(null, $content);
                    return "<div style='padding:10px 10px 0'>$card</div>";
                }
            );
            $grid->disableCreateButton();
            $grid->disableRowSelector();
            $grid->actions(function (Grid\Displayers\Actions $actions) {
                $actions->disableDelete();
                $actions->disableQuickEdit();
                if ($actions->row->audit_status==0) {
                    $actions -> append(new AuditActions($actions->row->table));
                }
            });
            $grid->selector(function (Grid\Tools\Selector $selector) {
                $selector->selectOne('audit_status', '审核状态', trans('global.options.audit_status'));
            });
        });
    }
}

